package top.goldenyear.porpoise.system.permission.controller.admin;

import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.*;
import org.noear.solon.validation.annotation.Validated;
import top.goldenyear.porpoise.common.core.model.Ret;
import top.goldenyear.porpoise.framework.web.core.controller.BaseController;
import top.goldenyear.porpoise.framework.web.core.model.query.QPage;
import top.goldenyear.porpoise.system.permission.dto.RoleAccountReq;
import top.goldenyear.porpoise.system.permission.dto.RoleAccountsReq;
import top.goldenyear.porpoise.system.permission.service.AccountRoleService;

import java.util.List;

/**
 * 账户角色表 Controller 控制层
 *
 * @author airhead
 * @since 2024-10-13
 */
@Component(tag = "adminApi")
@Mapping("/permission/accountRole")
@Slf4j
public class AccountRoleAdminController extends BaseController {
  @Inject private AccountRoleService service;

  @Post
  @Mapping("add")
  public Ret add(@Body RoleAccountReq roleAccountReq) {
    return Ret.okWithData(service.addRoleAccount(roleAccountReq));
  }

  @Post
  @Put
  @Mapping("update")
  public Ret update(@Validated @Body RoleAccountsReq roleAccountsReq) {
    return Ret.okWithData(service.updateRoleAccount(roleAccountsReq));
  }

  @Post
  @Delete
  @Mapping("deleteByUser")
  public Ret deleteByUser(@Param Integer userId) {
    return Ret.okWithData(service.deleteByUser(userId));
  }

  @Post
  @Delete
  @Mapping("deleteByUsers")
  public Ret deleteByUsers(@Param List<Integer> userIds) {
    return Ret.okWithData(service.deleteByUsers(userIds));
  }


  @Post
  @Delete
  @Mapping("deleteByRole")
  public Ret deleteByRole(@Param Integer roleId) {
    return Ret.okWithData(service.deleteByRole(roleId));
  }

  @Get
  @Mapping("list")
  public Ret list(Integer roleId) {
    return Ret.okWithData(service.listRoleAccount(roleId));
  }

  @Get
  @Mapping("paginate")
  public Ret paginate(Integer roleId, QPage qPage) {
    return Ret.okWithData(service.paginateRoleAccount(roleId, qPage));
  }
}
